# encoding=utf-8
# author:梁子龙
import os
from datetime import timedelta

from celery.schedules import crontab
from user.models import UserModel
from celery_tasks import app

# os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'django-celery-beat')
# add_tasks.py

# celery -A proj.celery_tasks  worker -l info -P gevent
# 命令：
# celery -A celerys worker -l info -P eventlet
# celery -A proj.home_task beat -l INFO --scheduler django_celery_beat.schedulers:DatabaseScheduler
app.conf.beat_schedule = {
    'add-task': {
        # 要执行的方法所在的路径
        'task': 'celery_tasks.home_task.arrange_task',  # 要执行的任务

        # 每隔三秒启动一次
        'schedule': timedelta(seconds=3),
        # 参数
        'args': (),
    },
}


# celery -A proj.celery_tasks  worker -l info -P gevent
# celery beat -A proj.home_task -l info
# @app.task
# def arrange_task():
#     user = UserModel.objects.filter(username="django").first()
#     staff = user.is_staff
#     if staff == True:
#         user.is_staff = False
#         user.save()
#     else:
#         user.is_staff = True
#         user.save()
#     print(staff, "flag")
